const getFileName = function (path) {
      var pos1 = path.lastIndexOf('/')
      var pos2 = path.lastIndexOf('\\')
      var pos = Math.max(pos1, pos2)
      if (pos < 0) {
        return path
      }
      else {
        let tempPath = path.substring(pos + 1);
        return tempPath.substring(0, tempPath.lastIndexOf("."));
      }
    }

const getimgname = function(imgurl){
	//let tempPath = imgurl.substring(0 + 1);
	return imgurl.substring(0, imgurl.lastIndexOf("."));
}

const uniUpLoadFile = async (imgurl) => {
	let promise;

	// 请求本地文件系统对象
	
	promise =await  new Promise((resolve, reject)=>{
		plus.downloader.createDownload( imgurl, {}, function ( d, status ) {
			
		  if ( status == 200 ) { // 下载成功  
				console.log(d);
		        var  doenfile =  plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename));
				//console.log("doenfile",doenfile)
				console.log("d.filename",d.filename)
				
				//imgdownurl = d.filename;
				console.log("plus.io.convertLocalFileSystemURL(d.filename)",plus.io.convertLocalFileSystemURL(d.filename))
				resolve(d.filename);
		    } else {//下载失败 
		        plus.downloader.clear();
				reject('false');
		    }
			
		}).start();
	})
	return promise;
	
	
	
	
	
	// var imgdownurl = '';
	// var dtask = plus.downloader.createDownload( imgurl, {}, function ( d, status ) {
		
	//   if ( status == 200 ) { // 下载成功  
	// 		console.log(d);
	//         var  doenfile =  plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename));
	// 		//console.log("doenfile",doenfile)
	// 		console.log("d.filename",d.filename)
			
	// 		imgdownurl = d.filename;
	// 		console.log("plus.io.convertLocalFileSystemURL(d.filename)",plus.io.convertLocalFileSystemURL(d.filename))
	// 		return imgdownurl;
	//     } else {//下载失败 
	//         plus.downloader.clear();
	// 		imgdownurl = null;
	// 		return imgdownurl;
	//     }
		
	// });
	// dtask.start();
	
}

	
	module.exports = {
	    getFileName,
		getimgname
	}